const install = (Vue, vm) => {
	const isWeiXin = () => {
	    var ua = window.navigator.userAgent.toLowerCase();
	    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
	        return true;
	    } else {
	        return false;
	    }
	}
	// 判断环境
	const environment = () => {
	    let platform = '';
	    var u = navigator.userAgent;
	    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
	    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
	    if (isiOS) {
	        platform = 'ios'
	    } else if (isAndroid) {
	        platform = 'android'
	    }
	    return platform
	}
	//登录
	let getLocationName = (params = {}) => {
		let result = {};
		let amap_key = "914e53e8abb36cddf40df408b4e41912"
		uni.getLocation({
			type:'gcj02',
			success(pos) {
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/regeo',
					data: {
						location: `${pos.longitude},${pos.latitude}`,
						key: amap_key,
						poitype: '城市',
					},
					success(res) {
						result = {
							longitude: pos.longitude,
							latitude: pos.latitude,
							city: res.data.regeocode.addressComponent.city
						}
						uni.setStorageSync('lat', result.latitude);
						uni.setStorageSync('lng', result.longitude);
						uni.setStorageSync('city', result.city);
					}
				});
			}
		});
		
	};
	vm.$u.utils = {
		isWeiXin,
		getLocationName,
		environment
	}
}
export default {
	install
}
